<?php

namespace App\Console\Commands;

use App\Console\Commands\Common\CommonCommand;
use App\Models\Article\ArticleClassify;
use App\Models\Article\ArticleInfo;
use App\Models\Setting\SysSetting;
use App\Models\User\User;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class UpdateCache extends CommonCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cleardownload';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle() {

        $records = (new ArticleClassify())->getLst(['pid'=>0])->with('children')->get(['id','name','pid','sort']);
        Cache::put('classifies', $records);

        $records = SysSetting::whereIn('key',['first','month','quarter','year'])->pluck('item_desc','key')->toArray();
        Cache::put('memberType', $records);

        Cache::put('countArticle', ArticleInfo::where('publish_at','<=',date('Y-m-d H:i:s'))->orderByDesc('id')->first()->id??1);

        return 0;
    }
}
